package com.tudouji.project.quality.controller;

import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.quality.domain.Qarecord;
import com.tudouji.project.quality.service.IQarecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 质检记录Controller
 *
 * @author tudouji
 * @date 2022-11-01
 */
@RestController
@RequestMapping("/quality/qarecord")
public class QarecordController extends BaseController
{
    @Autowired
    private IQarecordService qarecordService;

    /**
     * 查询质检记录列表
     */
    @PreAuthorize("@ss.hasPermi('quality:qarecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(Qarecord qarecord)
    {
        startPage();
        List<Qarecord> list = qarecordService.selectQarecordList(qarecord);
        return getDataTable(list);
    }

    /**
     * 导出质检记录列表
     */
    @PreAuthorize("@ss.hasPermi('quality:qarecord:export')")
    @Log(title = "质检记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Qarecord qarecord)
    {
        List<Qarecord> list = qarecordService.selectQarecordList(qarecord);
        ExcelUtil<Qarecord> util = new ExcelUtil<Qarecord>(Qarecord.class);
        return util.exportExcel(list, "qarecord");
    }

    /**
     * 获取质检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('quality:qarecord:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(qarecordService.selectQarecordById(guid));
    }

    /**
     * 新增质检记录
     */
    @PreAuthorize("@ss.hasPermi('quality:qarecord:add')")
    @Log(title = "质检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Qarecord qarecord)
    {
        return toAjax(qarecordService.insertQarecord(qarecord));
    }

    /**
     * 修改质检记录
     */
    @PreAuthorize("@ss.hasPermi('quality:qarecord:edit')")
    @Log(title = "质检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Qarecord qarecord)
    {
        return toAjax(qarecordService.updateQarecord(qarecord));
    }

    /**
     * 删除质检记录
     */
    @PreAuthorize("@ss.hasPermi('quality:qarecord:remove')")
    @Log(title = "质检记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(qarecordService.deleteQarecordByIds(guids));
    }


}
